package com.example.yu.circlers_demo;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private ImageView iv_show;
    private int widthPixels;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv_show = findViewById(R.id.iv_show);
        //得到资源  得到显示指标
        widthPixels = getResources().getDisplayMetrics().widthPixels;
        initView();
    }

    private void initView() {
        Bitmap bitmap = Bitmap.createBitmap(widthPixels, widthPixels, Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bitmap);

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeWidth(20);
        paint.setAntiAlias(true);

        canvas.drawCircle(widthPixels/2,widthPixels/2,widthPixels/2,paint);

        Bitmap bit = BitmapFactory.decodeResource(getResources(), R.mipmap.ff);

//        Matrix matrix = new Matrix();
//        matrix.setSkew(0.4f,0.4f);

        //挖出Bitmap那一块内容
        Rect rect = new Rect(0,0,bit.getWidth(),bit.getHeight());
        //需要将Bitmap 绘制到画布的那一块区域
        RectF rectF = new RectF(0,0,widthPixels,widthPixels);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bit,rect,rectF,paint);
        iv_show.setImageBitmap(bitmap);
    }
}
